package xyz.yuanjilu.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import redis.clients.jedis.ShardedJedis;
import redis.clients.jedis.ShardedJedisPool;
import xyz.yuanjilu.service.RedisService;

@Service
public class RedisServiceImpl implements RedisService{
	@Autowired
	ShardedJedisPool shardedJedisPool;
	
	@Override
	public Object get(String cacheName, String key) {
		ShardedJedis resource = shardedJedisPool.getResource();
		
		return resource.get(key+"");
	}

	@Override
	public <T> T get(String cacheName, String key, Class<T> type) {
		ShardedJedis resource = shardedJedisPool.getResource();
		
		return (T)resource.get(key);
	}

	@Override
	public void put(String cacheName, String key, String value) {
		ShardedJedis resource = shardedJedisPool.getResource();
		if (resource.exists(key)) {
			resource.del(key);
		}
		resource.lpush(key, value);
	}

	@Override
	public void clear(String cacheName) {
		ShardedJedis resource = shardedJedisPool.getResource();
	}

}
